<?php

use kzo\base\widgets\ui\common\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use kzo\base\models\statics\EntityModelStatus;
use kzo\base\models\statics\OperationEvent;
use kzo\base\widgets\ui\common\grid\ActionColumn;

/* @var $this yii\web\View */
/* @var $searchModel common\models\c2\search\InventoryDeliveryNoteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model common\models\c2\search\InventoryDeliveryNoteSearch */

$this->title = Yii::t('app.c2', 'Inventory Delivery Notes');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="inventory-delivery-note-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,

        'pjax' => true,
        'hover' => true,
        'showPageSummary' => true,
        'panel' => ['type' => GridView::TYPE_SUCCESS, 'heading' => Yii::t('app.c2', 'Items')],
        'toolbar' => [
            [
                'content' =>
                    Html::a('<i class="fas fa-plus"></i>', ['edit'], [
                        'class' => 'btn btn-success',
                        'title' => Yii::t('app.c2', 'Add'),
                        'data-pjax' => '0',
                    ]) . ' ' .
                    Html::button('<i class="fas fa-minus"></i>', [
                        'class' => 'btn btn-danger',
                        'title' => Yii::t('app.c2', 'Delete Selected Items'),
                        'onClick' => "jQuery(this).trigger('" . OperationEvent::DELETE_BY_IDS . "', {url:'" . Url::toRoute('multiple-delete') . "'});",
                    ]) . ' ' .
                    Html::a('<i class="fas fa-redo"></i>', Url::current(), [
                        'class' => 'btn btn-outline-secondary',
                        'title' => Yii::t('app.c2', 'Reset Grid')
                    ]),
                'options' => ['class' => 'btn-group mr-2']
            ],
            '{export}',
            '{toggleData}',
        ],
        'exportContainer' => ['class' => 'btn-group mr-2'],
        'exportConfig' => [],
        'columns' => [
            ['class' => 'kartik\grid\CheckboxColumn'],
            ['class' => 'kartik\grid\SerialColumn'],
            [
                'class' => 'kartik\grid\ExpandRowColumn',
                'value' => function ($model, $key, $index, $column) {
                    return GridView::ROW_COLLAPSED;
                },
                'detail' => function ($model, $key, $index, $column) {
                    return Yii::$app->controller->renderPartial('_detail', ['model' => $model]);
                },
            ],
            'id',
            // 'type',
            'code',
            'label',
            // [
            //     'attribute' => 'warehouse_id',
            //     'value' => function ($model) {
            //         return $model->warehouse->name;
            //     }
            // ],
            // 'sales_order_id',
            // 'customer_id',
            [
                'attribute' => 'customer_id',
                'value' => function ($model) {
                    return $model->customer->username;
                }
            ],
            'occurrence_date',
            // 'grand_total',
            // 'contact_man',
            // 'cs_name',
            // 'sender_name',
            // 'financial_name',
            // 'payment_method',
            // 'delivery_method',
            // 'remote_ip',
            // 'updated_by',
            // 'created_by',

            // 'state',
            // 'status',
            // 'position',
            [
                'attribute' => 'created_by',
                'value' => function ($model) {
                    return $model->creator->username;
                }
            ],
            [
                'attribute' => 'memo',
                'format' => 'html'
            ],
            'created_at',
            [
                'attribute' => 'state',
                'class' => '\kartik\grid\EditableColumn',
                'editableOptions' => [
                    'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                    'formOptions' => ['action' => Url::toRoute('editColumn')],
                    'data' => \common\models\c2\statics\InventoryDeliveryNoteState::getHashMap('id', 'label'),
                    'displayValueConfig' => \common\models\c2\statics\InventoryDeliveryNoteState::getHashMap('id', 'label'),
                ],
                'filter' => \common\models\c2\statics\InventoryDeliveryNoteState::getHashMap('id', 'label'),
                'value' => function ($model) {
                    return \common\models\c2\statics\InventoryDeliveryNoteState::getLabel($model->state);
                }
            ],
            // 'updated_at',
            // [
            //     'attribute' => 'status',
            //     'class' => '\kartik\grid\EditableColumn',
            //     'editableOptions' => [
            //         'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
            //         'formOptions' => ['action' => Url::toRoute('editColumn')],
            //         'data' => EntityModelStatus::getHashMap('id', 'label'),
            //         'displayValueConfig' => EntityModelStatus::getHashMap('id', 'label'),
            //     ],
            //     'filter' => EntityModelStatus::getHashMap('id', 'label'),
            //     'value' => function ($model) {
            //         return $model->getStatusLabel();
            //     }
            // ],
            [
                'class' => ActionColumn::className(),
                'width' => '250px',
                'template' => '{update} {output} {finish} {print} {delete}',
                'buttons' => [
                    'update' => function ($url, $model, $key) {
                        return Html::a('<span class="fas fa-pencil-alt"></span>', ['edit', 'id' => $model->id], [
                            'title' => Yii::t('app', 'Info'),
                            'data-pjax' => '0',
                        ]);
                    },
                    'output' => function ($url, $model, $key) {
                        return Html::a(Yii::t('app.c2', 'Warehouse Output'), [
                                // '/delivery-note/output', 'id' => $model->id
                                '/delivery-note/output', 'id' => $model->id
                        ], [
                            'title' => Yii::t('app.c2', 'Warehouse Output'),
                            'data-pjax' => '0',
                            'class' => 'btn btn-sm btn-primary'
                        ]);
                    },
                    'finish' => function ($url, $model, $key) {
                        return Html::a(Yii::t('app.c2', 'Finish'), ['edit', 'id' => $model->id], [
                            'title' => Yii::t('app.c2', 'Finish'),
                            'data-pjax' => '0',
                            'class' => 'btn btn-sm btn-success'
                        ]);
                    },
                    'print' => function ($url, $model, $key) {
                        return Html::a(Yii::t('app.c2', 'Print'), ['print', 'id' => $model->id], [
                            'title' => Yii::t('app.c2', 'Print'),
                            'data-pjax' => '0',
                            'class' => 'btn btn-sm',
                            'target' => '_blank'
                        ]);
                    },
                ]
            ],

        ],
    ]); ?>

</div>
